﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PojProject.Pojs
{
    public class Poj2109
    {
        private double n;
        private double p;

        // k^n = p ( 1<=n<=200; 1<=p<10^101 ; 1<=k<=10^9)
        public Poj2109(double n, double p)
        {
            this.n = n;
            this.p = p;
        }

        public int Play()
        {
            var maxCount = Math.Pow(10, 9);

            for (int i = 1; i < maxCount; i++)
            {
                double temp = 0;
                if ((temp =  Math.Pow(i, n)) >= p)
                {
                    if (Math.Abs(p - temp) > Math.Abs(p - Math.Pow(i - 1, n)))
                    {
                        return i - 1;
                    }
                    else
                    {
                        return i;
                    }
                }
            }

            return 0;
        }
    }
}
